package pattern5.ProducerConsumer.demo1.msgServer;

import utils.PrintUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @创建人 liweijia
 * @创建时间 2022/7/30
 * @描述 程序的主要用途
 */
public abstract class Consumer extends Thread {

    /**
     * 消息管理者
     */
    private final MsgManager msgManager;


    protected Consumer(MsgManager msgManager) {
        this.msgManager = msgManager;
    }

    @Override
    public void run() {
        PrintUtil.print("消费者启动");
        while (true) {
            Msg msg = msgManager.take();
            consumerTask(msg);
        }
    }

    /**
     * 处理消息的逻辑，给具体的消费者去实现
     *
     * @param msg
     */
    protected abstract void consumerTask(Msg msg);
}
